package com.llyb.lease.web.admin.custom.interceptors;

import com.llyb.lease.common.exception.LeaseException;
import com.llyb.lease.common.jwt.JwtUtils;
import com.llyb.lease.common.result.ResultCodeEnum;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String accessToken = request.getHeader("access_token");
        if (ObjectUtils.isEmpty(accessToken)) {
            throw new LeaseException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }
        JwtUtils.parseToken(accessToken);
        return true;
    }
}
